package com.babasport.bean.product;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class ProductType /* extends BaseObject */{

	private static final long serialVersionUID = 791764455634193379L;

	/** 类别ID **/
	private Integer typeId;
	/** 类别名称 **/
	private String name;
	/** google搜索用 **/
	private String note;
	/** 是否可见/删除 **/
	private Boolean visible = true;
	/** 子类 **/
	private Set<ProductType> childs = new HashSet<ProductType>();
	/** 父类 **/
	private ProductType parent;

	private Set<ProductInfo> products = new HashSet<ProductInfo>();

	@OneToMany(mappedBy = "type", cascade = CascadeType.REMOVE)
	public Set<ProductInfo> getProducts() {
		return products;
	}

	public void setProducts(Set<ProductInfo> products) {
		this.products = products;
	}

	public ProductType() {
		super();
	}

	public ProductType(Integer typeId) {
		super();
		this.typeId = typeId;
	}

	public ProductType(String name, String note) {
		super();
		this.name = name;
		this.note = note;
	}

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "parentID")
	public ProductType getParent() {
		return parent;
	}

	public void setParent(ProductType parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = { CascadeType.REFRESH, CascadeType.REMOVE }, mappedBy = "parent")
	public Set<ProductType> getChilds() {
		return childs;
	}

	public void setChilds(Set<ProductType> childs) {
		this.childs = childs;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getTypeId() {
		return typeId;
	}

	public void setTypeId(Integer typeId) {
		this.typeId = typeId;
	}

	@Column(length = 36, nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(length = 200)
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Column(nullable = false)
	public Boolean getVisible() {
		return visible;
	}

	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

}
